package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.happy.cat.common.utils.SecurityUtils;
import com.happy.cat.common.utils.StringUtils;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import com.happy.cat.project.system.domain.CatExchangeMoney;
import com.happy.cat.project.system.service.ICatExchangeMoneyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 提现设置Controller
 *
 * @author verne
 * @date 2020-07-18
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/exchangeMoney" )
@Api("提现设置 API")
public class CatExchangeMoneyController extends BaseController {

    private final ICatExchangeMoneyService iCatExchangeMoneyService;

    /**
     * 查询提现设置列表
     */
    @ApiOperation(value = "查询提现设置列表",notes = "查询提现设置列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:exchangeMoney:list')")
    @GetMapping("/list")
    public TableDataInfo list(CatExchangeMoney catExchangeMoney)
    {
        startPage();
        LambdaQueryWrapper<CatExchangeMoney> lqw = new LambdaQueryWrapper<CatExchangeMoney>();
        if (StringUtils.isNotBlank(catExchangeMoney.getApplyDaily())){
            lqw.eq(CatExchangeMoney::getApplyDaily ,catExchangeMoney.getApplyDaily());
        }
        if (catExchangeMoney.getFullPet() != null){
            lqw.eq(CatExchangeMoney::getFullPet ,catExchangeMoney.getFullPet());
        }
        if (catExchangeMoney.getRatePet() != null){
            lqw.eq(CatExchangeMoney::getRatePet ,catExchangeMoney.getRatePet());
        }
        if (catExchangeMoney.getCardinalPet() != null){
            lqw.eq(CatExchangeMoney::getCardinalPet ,catExchangeMoney.getCardinalPet());
        }
        if (catExchangeMoney.getDailyBoutPet() != null){
            lqw.eq(CatExchangeMoney::getDailyBoutPet ,catExchangeMoney.getDailyBoutPet());
        }
        if (catExchangeMoney.getDailyMoney() != null){
            lqw.eq(CatExchangeMoney::getDailyMoney ,catExchangeMoney.getDailyMoney());
        }
        if (catExchangeMoney.getFullOrder() != null){
            lqw.eq(CatExchangeMoney::getFullOrder ,catExchangeMoney.getFullOrder());
        }
        if (catExchangeMoney.getOrderRate() != null){
            lqw.eq(CatExchangeMoney::getOrderRate ,catExchangeMoney.getOrderRate());
        }
        if (catExchangeMoney.getCardinalOrder() != null){
            lqw.eq(CatExchangeMoney::getCardinalOrder ,catExchangeMoney.getCardinalOrder());
        }
        if (catExchangeMoney.getDailyBoutOrder() != null){
            lqw.eq(CatExchangeMoney::getDailyBoutOrder ,catExchangeMoney.getDailyBoutOrder());
        }
        if (catExchangeMoney.getDailyMoneyOrder() != null){
            lqw.eq(CatExchangeMoney::getDailyMoneyOrder ,catExchangeMoney.getDailyMoneyOrder());
        }
        if (StringUtils.isNotBlank(catExchangeMoney.getChannel())){
            lqw.eq(CatExchangeMoney::getChannel ,catExchangeMoney.getChannel());
        }
        if (catExchangeMoney.getCreateDate() != null){
            lqw.eq(CatExchangeMoney::getCreateDate ,catExchangeMoney.getCreateDate());
        }
        if (catExchangeMoney.getStatus() != null){
            lqw.eq(CatExchangeMoney::getStatus ,catExchangeMoney.getStatus());
        }
        List<CatExchangeMoney> list = iCatExchangeMoneyService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出提现设置列表
     */
    @ApiOperation(value = "导出提现设置列表",notes = "导出提现设置列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:exchangeMoney:export')" )
    @Log(title = "提现设置" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(CatExchangeMoney catExchangeMoney) {
        LambdaQueryWrapper<CatExchangeMoney> lqw = new LambdaQueryWrapper<CatExchangeMoney>(catExchangeMoney);
        List<CatExchangeMoney> list = iCatExchangeMoneyService.list(lqw);
        ExcelUtil<CatExchangeMoney> util = new ExcelUtil<CatExchangeMoney>(CatExchangeMoney. class);
        return util.exportExcel(list, "exchangeMoney" );
    }

    /**
     * 获取提现设置详细信息
     */
    @ApiOperation(value = "获取提现设置详细信息",notes = "获取提现设置详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:exchangeMoney:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iCatExchangeMoneyService.getById(id));
    }

    /**
     * 新增提现设置
     */
    @ApiOperation(value = "新增提现设置",notes = "新增提现设置",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:exchangeMoney:add')" )
    @Log(title = "提现设置" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CatExchangeMoney catExchangeMoney) {
        catExchangeMoney.setCreateDate(new Date());
        catExchangeMoney.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iCatExchangeMoneyService.save(catExchangeMoney) ? 1 : 0);
    }

    /**
     * 修改提现设置
     */
    @ApiOperation(value = "修改提现设置",notes = "修改提现设置",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:exchangeMoney:edit')" )
    @Log(title = "提现设置" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CatExchangeMoney catExchangeMoney) {
        catExchangeMoney.setCreateDate(new Date());
        catExchangeMoney.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iCatExchangeMoneyService.updateById(catExchangeMoney) ? 1 : 0);
    }

    /**
     * 删除提现设置
     */
    @ApiOperation(value = "删除提现设置",notes = "删除提现设置",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:exchangeMoney:remove')" )
    @Log(title = "提现设置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iCatExchangeMoneyService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
